﻿@{
    ViewBag.Title = "RoleList";
    Layout = "~/Views/Shared/_BasicLayout.cshtml";
}

<script type="text/javascript">
    $(function () {
        var height = $("#divTotal").height();
        var master = $("#master").height();
        var content = parseFloat(height) - parseFloat(master) - 30;
        $("#tbList").css("height", content);
    });
    $(function () {
        $("#tbList").datagrid({
            url: '/Role/GetRoleList',
            loadMsg: '数据加载中请稍后……',
            pagination: true,
            rownumbers: true,
            idField: "Id",
            singleSelect: true,
            pageSize: 10,
            pageList: [10, 20, 30],
            columns: [[
                {
                    field: 'ck', checkbox: true, width: 30
                },
                {
                    field: 'Name', title: '角色名称', sortable: true, align: "center", width: 200,
                    editor: {
                        type: "validatebox",
                        options: {
                            required: true
                        }
                    }

                }, {
                    field: 'AddTime', title: '修改时间', align: "center", width: 240,



                }, {
                    field: 'Remark', title: '备注', align: "center", width: 600,
                    editor: {
                        type: "text"
                    }
                }
            ]],
            onAfterEdit: function (rowIndex, rowData, changes) {
                if (editAction == "edit") {
                    com.ajax({
                        url: "/Role/EditRole",
                        data: rowData,
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                        }
                    });
                } else if (editAction == "add") {

                    com.ajax({
                        url: "/Role/AddRole",
                        data: rowData,
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                        }
                    });
                }
                editRow = undefined;


            }


        })
    })
</script>
<script type="text/javascript">

    editRow = undefined;
    editAction = undefined;
    function funcAdd() {
        //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
        if (editRow != undefined) {

        }
        //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
        if (editRow == undefined) {
            $("#tbList").datagrid("insertRow", {
                index: 0, // index start with 0
                row: {

                }
            });
            //将新插入的那一行开户编辑状态
            $("#tbList").datagrid("beginEdit", 0);

            //给当前编辑的行赋值
            editRow = 0;

            editAction = "add";
        }
    }
    function funcEdit() {

        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            if (editRow != undefined) {
            }
            else {
                var index = $("#tbList").datagrid('getRowIndex', row);
                //   var index = row.Id;
                $("#tbList").datagrid('beginEdit', index);
                editAction = "edit";
                editRow = index;
            }
        }
        else {
            com.message("information", "请选中一行");
        }
    }
    function funcSave() {
        $('#tbList').datagrid('endEdit', editRow);

    }
    function funcRemove() {
        $.messager.confirm('确认对话框', '您确定删除该权限吗？', function (r) {
            if (r) {
                var rowData = $("#tbList").datagrid("getSelected");
                if (rowData) {
                    com.ajax({
                        url: '/Role/DelRole',
                        data: { Id: rowData.Id },
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })

                        }

                    });
                }
            }
        });
    }
    function funcAssign() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {

            $.extend(com.dialogObj, { title: "分配权限", width: 500, height: 300, href: "/UI/BD/AssignPermWindow.aspx" });
            $("#assignPermDiv").dialog(
               com.dialogObj
            );
            $(top.document).find("#hidId").val(row.Id);
            console.log($(top.document).find("#hidId").val());
        }
        else {
            com.message("information", "请选中一行");
        }

    }

    function funAssignBtn() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            $.extend(com.dialogObj, { title: "分配按钮权限", width: 600, height: 400, href: "/UI/BD/AssignPermBtnWindow.aspx" });
            $("#assignPermDiv").dialog(com.dialogObj
                );
            $(top.document).find("#hidId").val(row.Id);
            // console.log($(top.document).find("#hidId").val());
        }
        else {
            com.message("information", "请选中一行");
        }
    }

    function funcAssignPer() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            top.wrapper.addTab("分配权限", "/Permission/AssignAllPerm?Id=" + row.Id);
        }
        else {
            com.message("information", "请选中一行");
        }
    }
</script>
<div id="divTotal" style="height: 100%; width: 100%">
    <div id="master" class="container_16" style="height: auto">
        <form id="form1"></form>
    </div>
    <table id="tbList" title="角色信息表 " style="width: 100%"></table>
</div>
<div id="assignPermDiv">
</div>
